﻿<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		  content="target-densitydpi=device-dpi, width=device-width,height=device-height, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0,shrink-to-fit=no" />
	<meta name="format-detection" content="telephone=no" />
	<!--em标准js代码，请放在页面的最上方，前面最好不要再有JS代码或JS文件-->
	<script type="text/javascript" src="/js/rem.js"></script>
	<link type="text/css" rel="stylesheet" href="/css/css.css" />
	<title>东易日盛装饰开业盛典</title>
	<link rel="stylesheet" type="text/css" href="/swiper/swiper.min.css" />
	<link rel="stylesheet" type="text/css" href="/swiper/swiper_style.css" />
	<link rel="stylesheet" type="text/css" href="/css/lottery.css" />
	<script type="text/javascript" src="/js/jquery-1.11.1.min.js"></script>
	<script src="/swiper/swiper.min.js"></script>
</head>

<style>
	.raffled{
		text-align: center;
		/*bgcolor: "#FFF2EE";*/
		background-color: #FFF2EE;
		height:2.2rem;
		z-index: 999999999;
		background-image: none;
		color: #242a4c;
		border-radius:10px;
		width: 94%;
	}
	.luckstyle{
		border-radius:10px;border:5px solid #DA2B00;background:#DA2B00;
	}
	.myhide{
		display: none;
	}
</style>

<body>

<div class="header">
	<a href="javascript:history.go(-1);" class="backa"></a>

	<a href="javascript:;" class="seta"></a>
</div>

<div class="draw-title">
	<div class="draw-title1">报名成功</div>
	<div class="draw-title2" id="userId">你的用户编号为:DY2125</div>
	<div class="draw-title3" id="cjResult">已经获取一次抽奖机会！马上抽奖</div>
</div>

<input type="hidden" id="userId0">

<div class="lottery">
	<div class="shanDeng" id="deng">
		<div id="luck" style="border-radius:10px;border:5px solid #DA2B00;background:#DA2B00;">
			<table border="1" bgcolor="#DA2B00" style="border:1px solid #DA2B00;" id="mytable">
				<tr>
					<td class="luck-unit luck-unit-0" id="prize0">
						<img src="/images/l_gift1.png" alt="" />
						<div>1.1元红包</div>
					</td>
					<td class="luck-unit luck-unit-1" id="prize1">
						<img src="/images/zWardS_fail2.png" alt="" />
						<div>谢谢你</div>
					</td>
					<td class="luck-unit luck-unit-2" id="prize2">
						<img src="/images/l_gift3.png" alt="" />
						<div>1.3元红包</div>
					</td>
				</tr>
				<tr>
					<td class="luck-unit luck-unit-7" id="prize7">
						<img src="/images/l_gift5.png" alt="" />
						<div>1.5元红包</div>
					</td>
					<td class="cjBtn" id="btn"></td>
					<td class="luck-unit luck-unit-3" id="prize3">
						<img src="/images/zWardS_fail2.png" alt="" />
						<div>谢谢你</div>
					</td>
				</tr>
				<tr>
					<td class="luck-unit luck-unit-6" id="prize6">
						<img src="/images/zWardS_fail2.png" alt="" />
						<div>谢谢你</div>
					</td>
					<td class="luck-unit luck-unit-5" id="prize5">
						<img src="/images/l_gift2.png" alt="" />
						<div>1.2元红包</div>
					</td>
					<td class="luck-unit luck-unit-4" id="prize4">
						<img src="/images/l_gift4.png" alt="" />
						<div>1.4元红包</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
</div>

<div class="award-tip">
	<div class="left">领奖说明：</div>
	<div class="right">兑奖条件：<br>1.抽奖人必须有新房未装修<br>
		2.报名即可参与抽奖<br>
		兑奖时间：6月26号前，客户量房后领取。</div>
</div>

<img src="/images/bodysd.jpg" alt="" class="sd">

<script type="text/javascript" src="/js/base.js"></script>
<!-- <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script> -->
<script>
	$(function () {
		getUserId();
		getAllPrize();
	});
	function getAllPrize() {
		$.ajax({
			url:"/prize/getAllPrize",
			method:"get",
			data:"",
			success:function (data){
				for(i=0;i<data.length;i++){
					$("#prize"+i).html("<img src=\"/images/result.png\" alt=\"\" />\n" +
							"\t\t\t\t\t\t<div>"+data[i].prizeDes+"</div>");
				}
			}
		})
	}

	var userId=0;
	function getUserId() {
		$.ajax({
			url:"/customer/getUserId",
			method:"get",
			data:"",
			success:function (data) {
				userId=data.userId;
				$("#userId0").val(data.userId)
				$("#userId").text("你的用户编号为:"+data.userId)

				if(data.isRaffled==0){
					$("#cjResult").text("您的抽奖机会已用完，感谢参与！")
					$("#deng").addClass("raffled")
					$.ajax({
						url:"/result/getResultByUserId",
						method:"get",
						data:{userId:data.userId},
						success:function (data) {
							$.ajax({
								url:"/prize/getPrizeById",
								method:"get",
								data:{
									prizeId:data.prizeId
								} ,
								success:function (data) {
									$("#deng").html("<img src=\"/images/result.png\" alt=\"\" /><br>您获得的奖品是："+data.prizeDes);
								}
							})
						}
					})
				} else {
					$("#cjResult").text("已经获取一次抽奖机会！马上抽奖")
				}
			}
		})
	}

	function updateIsRaffled() {
		if(cjCount>0){
			var userId=($("#userId0").val());
			$.ajax({
				url: "/customer/updateIsRaffled",
				method: "post",
				data: {userId:userId},
				success: function (data) {

				}
			})
		}
	}



	var luck = {
		index: 0, //当前转动到哪个位置，起点位置
		count: 0, //总共有多少个位置
		timer: 0, //setTimeout的ID，用clearTimeout清除
		speed: 20, //初始转动速度
		times: 0, //转动次数
		cycle: 50, //转动基本次数：即至少需要转动多少次再进入抽奖环节
		prize: -1, //中奖位置
		init: function (id) {
			if ($("#" + id).find(".luck-unit").length > 0) {
				$luck = $("#" + id);
				$units = $luck.find(".luck-unit");
				this.obj = $luck;
				this.count = $units.length;
				$luck.find(".luck-unit-" + this.index).addClass("active");
			};
		},

		roll: function () {
			var index = this.index;
			var count = this.count;
			var luck = this.obj;
			$(luck).find(".luck-unit-" + index).removeClass("active");
			index += 1;
			if (index > count - 1) {
				index = 0;
			};
			$(luck).find(".luck-unit-" + index).addClass("active");
			this.index = index;
			return false;
		},
		stop: function (index) {
			this.prize = index;
			return false;
		}
	};

	function roll() {
		luck.times += 1;
		luck.roll();
		if (luck.times > luck.cycle + 10 && luck.prize == luck.index) {
			clearTimeout(luck.timer);
			luck.prize = -1;
			luck.times = 0;
			click = false;
		} else {
			if (luck.times < luck.cycle) {
				luck.speed -= 10;
			} else if (luck.times == luck.cycle) {
				var index = Math.random() * (luck.count) | 0;
				if (index > 5) {
					index = 7;
				} else {
					index = 5;
				}
				luck.prize = index; //最终中奖位置
			} else {
				if (luck.times > luck.cycle + 10 && ((luck.prize == 0 && luck.index == 7) || luck.prize == luck.index +
						1)) {
					luck.speed += 110;
				} else {
					luck.speed += 20;
				}
			}
			if (luck.speed < 40) {
				luck.speed = 40;
			};

			luck.timer = setTimeout(roll, luck.speed);
		}
		return false;
	}

	var click = false;
	var cjCount = 0; //抽奖次数
	var rel=-1;
	window.onload = function () {
		luck.init('luck');
		$("#btn").click(function () {

			setTimeout(function () {
				$(".cover").removeClass("dis_no");
				$(".cover_box").removeClass("dis_no");
				$("body,html").css({
					"height": "100%",
					"overflow": "hidden"
				})
				//location.reload()
				$.ajax({
					url:"/prize/lucky",
					method:"get",
					data:"",
					success:function (data) {
						if(data.msg==2){
							/*jqalert("很抱歉，活动已结束！")
							return;*/
							cjCount=0
							location.href="/prize/back405"
						} else {
							var rel=data.result;

							prize=rel
							luck.stop(rel.prizeId)
							setTimeout(function () {
								$.ajax({
									url:"/result/addNewResult",
									method:"post",
									data:{
										userId:userId,
										prizeId:rel.prizeId
									},
									success:function (data){
										if(data>0){
											jqtoast("请于2020年6月7日18:00前到店领取，过期作废")
										}
									}
								})
								$("#cjResult").text("您的抽奖机会已用完，感谢参与！")
								$("#deng").addClass("raffled")
								$("#deng").html("<img src=\"/images/result.png\" alt=\"\" /><br>您获得的奖品是："+rel.prizeDes);
							},2000)

							cjCount++;
							updateIsRaffled();
						}

					}
				})
			}, 2000);



			if (click) {
				return false;
			} else {
				luck.speed = 100;
				roll();
				click = true;
				return false;
			}



		});
	};

	//			轮播图
	var swiper = new Swiper('.draw-container', {
		direction: "vertical",
		autoplay: true,
		loop: true,
	});

	//ios弹窗位置调整
	$("input").bind('focus', function () {
		var top = document.body.scrollTop;
		$(window).scrollTop(top);
	})
	$("input").bind('blur', function () {
		var top = document.body.scrollTop;
		$(window).scrollTop(top);
	})
	//关闭弹窗
	$(".close").on("click", function () {
		$(".cover").addClass("dis_no");
		$(".cover_box").addClass("dis_no");
		$("body,html").css({
			"height": "100%",
			"overflow": "auto"
		})
	})
	$("#form_insure").on("click", function () {
		$(".cover_box").addClass("dis_no");
		$(".result_box").removeClass("dis_no");
		$("body,html").css({
			"height": "100%",
			"overflow": "hidden"
		})
	})
</script>
</body>

</html>